<?php
class groups {

	function groups() {
		
	}
	function edit(){
		$view=$this->jieku->getView();
		$view->add("abc","123");
	}
	function get(){
		$view=$this->jieku->getView();
		$db=$this->jieku->getDB();
		$db->query(JDBTool::select(array("id","groupname","intro"),'sys_group',"",true));
		$groupList=$db->getAll();
		$view->add("groupList",$groupList);
	}
	function create(){
		$db=$this->jieku->getDB();
		$group[groupname]=$this->jieku->var[groupname];
		$group[intro]=$this->jieku->var[intro];
		$db->exec(JDBTool::insert("sys_group",$group,true));
		echo "true";
	}
	function delete(){
		$db=$this->jieku->getDB();
		$group[id]=$this->jieku->var[id];
		$db->exec(JDBTool::delete("sys_group",$group,true));
		echo "success";
	}
	function safeform(){
		$view=$this->jieku->getView();
		$db=$this->jieku->getDB();
		$group['id']=$this->jieku->var[id];		
		$db->query(JDBTool::select("*","sys_group",$group,true));
		$groupre=$db->next();
		$groupre['control'] = unserialize($groupre[control]);
		
		$db->query(JDBTool::select('*', 'sys_menus', "pid=0", true));//取得所有父级菜单
		$menus = $db->getAll();
		$powers = $groupre['control']['menus'];//权限数组
		$view->add('powers', $powers);
		$view->add('menus', $menus);

		$view->add("group",$groupre);
	}
	function updatesafe(){
		$db=$this->jieku->getDB();
		$group[id]=$this->jieku->var[id];
		$group[control]=serialize($this->jieku->var[control]);
		$db->exec(JDBTool::update("sys_group",$group,array(id=>$group[id]),true));
		$this->jieku->redirect("./?ctrl=groups&action=safeform&id=$group[id]");
	}
	function update(){
		$db=$this->jieku->getDB();
		$group=$this->jieku->var[group];
		$id=$this->jieku->var[gid];
		$db->exec(JDBTool::update("sys_group",$group,array(id=>$id),true));
		echo "true";
	}
}
?>